﻿using System;
using System.Collections.Generic;
//using System.Text;
using Petra.Gis.Geometry;
using Petra.Gis.DataServices;
using Petra.Gis.DataServices.Metadata;
//using Petra.Gis.ReferenceSystemServices;



namespace Petra.Gis.RenderingServices.PlanarBase 
{
  /// <summary>
  /// represents single map legend item organized as tree structure
  /// this object holds data and <c>Renderer</c> and implements data read
  /// data transformation and uses renderer to draw into map
  /// </summary>
  public abstract class LegendNode
  {
    protected string _title;
    protected LegendNodeType _nodeType;
    protected LegendNode _parent;
    //protected List<LegendNode> _childNodes;
    //protected object _data; //todo: change to Linq.IEnumerable or DataReader or DataTable
    //protected PlanarMap _map;

    public List<Renderer> Renderers;
    public string Description;


    #region constructors

    
    protected LegendNode(LegendNode parent, string title)
    {
      _parent = parent;
      _title = title;
      //_childNodes = new Dictionary<string, LegendNode>();
    }
    


    //protected internal LegendNode(LegendNode parent, object data)
    //{
    //  _parent = parent;
    //  _data = data;
    //}


    #endregion constructors


    #region public members

    /// <summary>
    /// intendation level of this node in legend viewport ;-)
    /// </summary>
    public int TreeLevel
    {
      get 
      {
        if (_parent == null)
          return 0;
        else
          return _parent.TreeLevel + 1;
      }
    }




    public MapLegend Legend
    {
      get 
      {
        if(_parent == null)
          return (MapLegend)this;
        else
          return _parent.Legend;
      }

    }




    public LegendNode Parent
    {
      get { return _parent; }
      set
      {
        if (value == null)
          throw new InvalidOperationException(@"error unsupported null as parent
                                                use RemoveNode() instead");

        _parent = value;
      }
    }




    public LegendNodeType NodeType
    { 
      get { return _nodeType; } 
    }



    public string Title
    {
      get { return _title; }
    }




    public abstract void RenderData();
    //{
    //  if (_data is SpatialDbCommand)
    //    renderDbData();
    //}


    #endregion public members




  }
  
}
